<?php

Database::SetPatchingSystem('oxygen','oxy_settings');
Database::AddPatcher('v','Version');

if (Database::BeginPatchingSystem()) {
	Database::ExecuteCreateStandardTable('oxy_settings','Version',Sql::Integer);
	Database::ExecuteInsert('oxy_settings','id',new ID(0));
}


if (Database::BeginPatch('v',1)) {
	Database::ExecuteCreateStandardTable('oxy_users'
			,'XUsername',Sql::String100
			,'XPassword',Sql::String100
			,'Email',Sql::String255
			,'XClass',Sql::String100
			,'idUserGroup',Sql::ID
			,'DateCreated',Sql::DateTime,'idCreatedBy',Sql::ID
			,'DateModified',Sql::DateTime,'idModifiedBy',Sql::ID
			);
	Database::ExecuteCreateStandardTable('oxy_user_groups'
			,'Name',Sql::String100
			,'idParent',Sql::ID
			,'DateCreated',Sql::DateTime,'idCreatedBy',Sql::ID
			,'DateModified',Sql::DateTime,'idModifiedBy',Sql::ID
			);
	Database::ExecuteInsert('oxy_user_groups','id',new ID(-1),'Name','visitors','DateCreated',new DateTime(),'idCreatedBy',new ID(4),'DateModified',new DateTime(),'idModifiedBy',new ID(4));
	Database::ExecuteInsert('oxy_user_groups','id',new ID(-2),'Name','users','DateCreated',new DateTime(),'idCreatedBy',new ID(4),'DateModified',new DateTime(),'idModifiedBy',new ID(4));
	Database::ExecuteInsert('oxy_user_groups','id',new ID(-3),'Name','administrators','DateCreated',new DateTime(),'idCreatedBy',new ID(4),'DateModified',new DateTime(),'idModifiedBy',new ID(4));
	Database::ExecuteInsert('oxy_user_groups','id',new ID(-4),'Name','developers','DateCreated',new DateTime(),'idCreatedBy',new ID(4),'DateModified',new DateTime(),'idModifiedBy',new ID(4));
	Database::ExecuteInsert('oxy_users','id',new ID(1),'idUserGroup',new ID(-1),'XUsername','visitor','XPassword','DFCF018F8E3AA133F615CEC11B554268','XClass','User','DateCreated',new DateTime(),'idCreatedBy',new ID(4),'DateModified',new DateTime(),'idModifiedBy',new ID(4));
	Database::ExecuteInsert('oxy_users','id',new ID(2),'idUserGroup',new ID(-2),'XUsername','user','XPassword','DFCF018F8E3AA133F615CEC11B554268','XClass','User','DateCreated',new DateTime(),'idCreatedBy',new ID(4),'DateModified',new DateTime(),'idModifiedBy',new ID(4));
	Database::ExecuteInsert('oxy_users','id',new ID(3),'idUserGroup',new ID(-3),'XUsername','administrator','XPassword','DFCF018F8E3AA133F615CEC11B554268','XClass','User','DateCreated',new DateTime(),'idCreatedBy',new ID(4),'DateModified',new DateTime(),'idModifiedBy',new ID(4));
	Database::ExecuteInsert('oxy_users','id',new ID(4),'idUserGroup',new ID(-4),'XUsername','developer','XPassword','DFCF018F8E3AA133F615CEC11B554268','XClass','User','DateCreated',new DateTime(),'idCreatedBy',new ID(4),'DateModified',new DateTime(),'idModifiedBy',new ID(4));


	Database::ApplyPatch();
}


if (Database::BeginPatch('v',2)) {
	Database::ExecuteCreateStandardTable('oxy_emails'
			,'XFrom',Sql::String255
			,'Rcpt',Sql::Text
			,'Subject',Sql::String255
			,'Body',Sql::Text
			,'DateSent',Sql::DateTime
			,'idSentBy',Sql::ID
			);
	Database::ApplyPatch();
}


if (Database::BeginPatch('v',3)) {
	Database::ExecuteCreateStandardTable('oxy_local_lemmas'
			,'Name',Sql::String255
			,'Overlap',Sql::Text
			);
	Database::ApplyPatch();
}


if (Database::BeginPatch('v',4)) {
	Database::ExecuteCreateTable('oxy_ids','TableName',Sql::String100 ,'LastID',Sql::ID);
	Database::ExecuteAddPrimaryKey('oxy_ids','TableName');
	Database::ApplyPatch();
}


if (Database::BeginPatch('v',5)) {
	Database::ExecuteAddFields('oxy_users','IsHidden',Sql::Boolean,'Comments',Sql::Text);
	Database::ExecuteUpdate('oxy_users','id>='.new Sql(1).' AND id<='.new Sql(4),'IsHidden',true);
	Database::ExecuteAddFields('oxy_user_groups','IsLocked',Sql::Boolean,'Comments',Sql::Text);
	Database::ExecuteUpdate('oxy_user_groups','id<='.new Sql(-1).' AND id>='.new Sql(-4),'IsLocked',true);
	Database::ApplyPatch();
}


if (Database::BeginPatch('v',6)) {
	Database::ExecuteAddFields('oxy_user_groups','XClass',Sql::String100);
	Database::ExecuteUpdateAll('oxy_user_groups','XClass','UserGroup');
	Database::ApplyPatch();
}


if (Database::BeginPatch('v',7)) {
	Database::ExecuteAddFields('oxy_users','IsBanned',Sql::Boolean);
	Database::ExecuteUpdateAll('oxy_users','IsBanned',false);
	Database::ApplyPatch();
}



?>